/*
ID:luongho3
LANG:JAVA
TASK:prefix
 */
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;


public class prefix {
	
	public static String[] primitives = new String[300];
	public static int nPrim;
	public static int[] longestAt = new int[300000];
	public static String sequence;

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("prefix.in"));
		PrintStream ps = new PrintStream(new File("prefix.out"));
		System.setOut(ps);
		nPrim = 0;
		do {
			String tmp = scanner.next();
			if (tmp.charAt(0) == '.') {
				break;
			}
			else {
				primitives[nPrim] = tmp;
				nPrim++;
			}
		} while (true);
		
		StringBuilder builder = new StringBuilder();
		while (scanner.hasNext()) {
			String tmp = scanner.next();
			tmp = tmp.trim();
			builder.append(tmp);
		}
		sequence = builder.toString();

		
		int maxLongestAt = 0;
		for (int i=1;i<=sequence.length();++i) {
			int idx = i - 1;
				for (int j=0;j<nPrim;++j) {
					int len = primitives[j].length();
					if (i>=len) {
						if (longestAt[i-len] == i-len) {
							String sub = sequence.substring(idx-len+1);
							if (sub.startsWith(primitives[j])) {
								longestAt[i] = i;
								if (longestAt[i] > maxLongestAt) {
									maxLongestAt = longestAt[i];
								}
								break;
							}					
						}
					}
				}
			
		}
		System.out.println(maxLongestAt);
		
		ps.close();
	}
	
}
